/**
 * 
 */
package com.jonosoft.photocast.viewer.web.client.ui.imagecollections;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.jonosoft.photocast.viewer.web.client.ImageCollection;
import com.jonosoft.photocast.viewer.web.client.ui.LibraryImage;

/**
 * TODO Add description ImageCollectionsByYearMenuItem (com.jonosoft.photocast.viewer.web.client.ui.imagecollections.ImageCollectionsByYearMenuItem)
 *
 * @author jon
 *
 */
public class ImageCollectionsByYearMenuItem extends ImageCollectionsMenuItem implements HasSubMenu {
	
	private String year = null;
	
	public ImageCollectionsByYearMenuItem(ImageCollection imageCollection, String year) {
		super(imageCollection);
		setYear(year);
		setText(year);
	}
	
	public String getYear() {
		return this.year;
	}
	
	public void setYear(String year) {
		this.year = year;
	}

	/**
	 * @see com.jonosoft.photocast.viewer.web.client.ui.imagecollections.HasSubMenu#getSubMenuItems()
	 */
	public List getSubMenuItems() {
		ArrayList submenuItems = new ArrayList();
		Iterator i = getListOfMonths().iterator();
		
		while (i.hasNext()) {
			Integer month = (Integer) i.next();
			submenuItems.add(new ImageCollectionsByMonthMenuItem(imageCollection, year.toString(), month.intValue()));
		}

		return submenuItems;
	}

	private List getListOfMonths() {
		ArrayList months = new ArrayList();
		Iterator i = imageCollection.iterator();
		Integer month = null;
		
		while (i.hasNext()) {
			month = new Integer(((LibraryImage) i.next()).getPhotoDate().getMonth());
			if (!months.contains(month))
				months.add(month);
		}

		return months;
	}
	
}
